﻿@model TestOnlineProject.Models.Entities.Section
@using TestOnlineProject.Models.Entities
@using TestOnlineProject.Common
@{
    ViewBag.Title = "Details";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
    if (!String.IsNullOrEmpty(ViewBag.Msg))
    {
    <script>        alert("@ViewBag.Msg")</script>
    }
}
<script>
    $(document).ready(function () {
        $("#deactivate").click(function () {
            var con = confirm("Are you sure you want to deactivate this section?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/Section/Deactivate")?ids=" + "@Model.SectionId" + "-",
                    type: 'GET',
                    success: function (data) {
                        if (data != null) {
                            alert(data);
                            window.location = "@Url.Content("~/Section/Details")?id=@Model.SectionId";
                        }
                    }
                })
            }
        }); $("#activate").click(function () {
            var con = confirm("Are you sure you want to activate this section?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/Section/Activate")?ids=" + "@Model.SectionId" + "-",
                    type: 'GET',
                    success: function (data) {
                        if (data != null) {
                            alert(data);
                            window.location = "@Url.Content("~/Section/Details")?id=@Model.SectionId";
                        }
                    }
                })
            }
        });
        $("#delete").click(function () {
            var con = confirm("Are you sure you want to delete this section?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/Section/Delete")?ids=" + "@Model.SectionId" + "-",
                    type: 'GET',
                    success: function (data) {
                        if (data != null) {
                            alert(data);
                            window.location="@Url.Content("~/Section/Index")?subjectId=" + @Model.SubjectId; 
                        }
                    }
                })
            }
        });
    })
    function SendReport(id) {
        $("#report_content").html("<input type=\"hidden\" name=\"sectionId\" id=\"vio_sectionId\" /> <div style=\"text-align: center\"> <input type=\"text\" name=\"message\" pattern=\".{5,100}\" required placeholder=\"Message\" title=\"The Message length is 5-100 characters.\" style=\"width: 330px\" /> <button type=\"submit\" value=\"Send\" class=\"btn\"> Send</button> </div>");
        $("#vio_sectionId").val(id);
    }
</script>
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home") / @Html.ActionLink("Subjects", "Index", "Subject", new { id = (ViewBag.Subject as Subject).SubjectId }, null)
    / @Html.ActionLink((ViewBag.Subject as Subject).Code, "Details", "Subject", new { id = (ViewBag.Subject as Subject).SubjectId }, null)
    / @Html.ActionLink("Sections", "Index", "Section", new { subjectId = (ViewBag.Subject as Subject).SubjectId }, null)
    / <span style="word-wrap: break-word">@Model.Name</span>
</div>
<br />
<div class="main_nav">
    <span><a href="@Url.Content("~/Section/Index")?subjectId=@Model.SubjectId&SectionId=@Model.SectionId">
        <img src="@Url.Content("~/Images/back button.png")" style="height:30px"/>
    </a></span>
</div>
<br />
@{
    if (!Model.IsActivated)
    {
    <div class="alert alert-error">
        <span>Deactivated.</span>
    </div>
    }
}
<table class="table table-bordered" style="table-layout: fixed">
    <tr>
        <td style="width: 150px; text-align: right">
            <span>Section</span>
        </td>
        <td>
            <div style="display: inline-block; float: right">
                <a href="#myModal" role="button" data-toggle="modal" class="vio_report" onclick="SendReport('@Model.SectionId')">
                    <img src="@Url.Content("~/Images/report.gif")"/></a>
            </div>
            <div style="word-break: break-all">
                @Html.DisplayFor(model => Model.Name)
            </div>
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Created By</span>
        </td>
        <td>
            @Html.ActionLink(Model.User.FullName, "Index", "Account", new { id = @Model.UserId }, new { target = "_blank" })
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Questions</span>
        </td>
        <td>
            @Html.ActionLink("Details", "Index", "Question", new { subjectId = @Model.SubjectId, sectionId = @Model.SectionId }, null)
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Created Time</span>
        </td>
        <td>
            @Html.DisplayFor(model => model.CreatedTime)
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Last Edit Time</span>
        </td>
        <td>
            @Html.DisplayFor(model => model.LastEditedTime)
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
        </td>
        <td>
            @{
                if (HttpContext.Current.User.IsInRole("1") || int.Parse(HttpContext.Current.User.Identity.Name) == Model.UserId)
                {
                @Html.ActionLink("Edit", "Edit", new { id = @Model.SectionId })

                    if (HttpContext.Current.User.IsInRole("1"))
                    {
                <span>|</span>
                        if (Model.IsActivated)
                        {
                <a href="#" id="deactivate">Deactivate</a>
                        }
                        else
                        {
                <a href="#" id="activate">Activate</a>
                        }
                    }
                <span>|</span>
                <a href="#" id="delete">Delete</a>
                }
            }
        </td>
    </tr>
</table>
<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
    aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
            ×</button>
        <h3 id="myModalLabel">
            Report</h3>
    </div>
    <div class="modal-body">
        @using (Ajax.BeginForm("Create", "Report", null, new AjaxOptions
        {
            InsertionMode = InsertionMode.Replace,
            HttpMethod = "GET",
            UpdateTargetId = "report_content",
        }, new
        {
            @class = "form-inline",
            id = "form_violation"
        }))
        {
            <div id="report_content">
                <input type="hidden" name="sectionId" id="vio_sectionId" />
                <div style="text-align: center">
                    <input type="text" name="message" pattern=".{5,100}" required placeholder="Message"
                        title="The Message length is 5-100 characters." style="width: 330px" />
                    <button type="submit" value="Send" class="btn">
                        Send</button>
                </div>
            </div>
        }
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">
            Close</button>
    </div>
</div>
